﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace _1stVATCWin
{
    public partial class Menu : Form
    {
        private string userName;
        public Menu(string userName)
        {
            InitializeComponent();
            this.userName = userName;
        }

        private void Menu_Load(object sender, EventArgs e)
        {
            Config file = new Config(Application.StartupPath + "\\config.ini");
            String connectionstring = file.ReadValue("Server", "conn"); // doc gia tri trong file config.ini tai truong [server], gia tri muon doc la con
            SqlConnection conn = new SqlConnection(connectionstring);
            string sql = "select * from NHANVIEN where IDnhanvien = @IDnhanvien";
            SqlCommand cmd = new SqlCommand(sql, conn);
            cmd.Parameters.AddWithValue("@IDnhanvien", userName);
            conn.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            if(reader.Read())
            {
               if((bool)reader["employeer"]==true)
               {
                   employeerToolStripMenuItem.Visible = true;
               }
               else
               {
                   employeerToolStripMenuItem.Visible = false;
               }
                if((bool)reader["product"]==true)
                {
                    productToolStripMenuItem.Visible = true;
                }
                else
                {
                    productToolStripMenuItem.Visible = false;
                }
                if((bool)reader["shopping"]==true)
                {
                    shoppingCartToolStripMenuItem.Visible = true;
                }
                else
                {
                    shoppingCartToolStripMenuItem.Visible = false;
                }
                if ((bool)reader["warranty"] == true)
                {
                    warrantyToolStripMenuItem.Visible = true;
                }
                else
                {
                    warrantyToolStripMenuItem.Visible = false;
                }
                if ((bool)reader["contact"] == true)
                {
                    contactToolStripMenuItem.Visible = true;
                }
                else
                {
                    contactToolStripMenuItem.Visible = false;
                }
                if ((bool)reader["news"] == true)
                {
                    newsToolStripMenuItem.Visible = true;
                }
                else
                {
                    newsToolStripMenuItem.Visible = false;
                }
                if ((bool)reader["statistic"]==true)
                {
                    statisticToolStripMenuItem.Visible = true;
                }
                else
                {
                    statisticToolStripMenuItem.Visible = false;
                }
                if ((bool)reader["provider"] == true)
                {
                    providerToolStripMenuItem.Visible = true;
                }
                else
                {
                    providerToolStripMenuItem.Visible = false;
                }
                reader.Close();
            }
            else
            {
                
            }
            conn.Close();
        }

        private void homeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Home f = new Home(userName);
            f.MdiParent = this;
            f.Show();
        }

        private void employeerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Employeer f = new Employeer();
            f.MdiParent = this;
            f.Show();
        }

        private void productToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SanPham f = new SanPham();
            f.MdiParent = this;
            f.Show();
        }

        private void shoppingCartToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Shopping_Cart f = new Shopping_Cart();
            f.MdiParent = this;
            f.Show();
        }

        private void warrantyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BaoHanh f = new BaoHanh();
            f.MdiParent = this;
            f.Show();
        }

        private void contactToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LienHe f = new LienHe();
            f.MdiParent = this;
            f.Show();
        }

        private void newsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ListTinTuc f = new ListTinTuc();
            f.MdiParent = this;
            f.Show();
        }

        private void statisticToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ThongKe f = new ThongKe();
            f.MdiParent = this;
            f.Show();
        }

        private void providerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ListNhaCungUng f = new ListNhaCungUng();
            f.MdiParent = this;
            f.Show();
        }
    }
}
